
(define (add-streams x y)
  (stream-map + x y))
(define (scale-stream str scalor)
  (stream-map (lambda (x) (* scalor x)) str))

(define (integral integrand initial-value dt)
  (define int
    (cons-stream initial-value
		 (add-streams (scale-stream integrand dt)
			      int))))
(define (RC R C dt)
  (lambda (i v0)
    (begin
      (define v
	(add-streams (scale-stream i R)
		     (integral (scale-stream i (/ 1 C))
			       v0
			       dt))))))

(define (zero-crossing sense-data)
  (define (sign-change-detector next-value last-value)
    (if(and (< next-value 0) (> last-value 0))
       -1
       (if (and (> next-value 0) (< last-value 0))
	   1
	   0)))
  (define x
    (stream-map sign-change-detector sense-data (stream-cdr sense-data))))
(define (smooth str)
  (stream-map (lambda (x y) (/ (+ x y) 2))
	      str
	      (stream-cdr str)))


